#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fileencoding=utf-8

import yaml
import os
from pyscript.controller import Task

def singleton(cls):
    
    def instance(*args, **kwargs):
        cls._id = cls._id if hasattr(cls, '_id') else cls(*args, **kwargs)
        return cls._id

    return instance


class Register(object):
    hashmap = dict()

    @classmethod
    def set(cls, key, value):
        cls.hashmap[key] = value

    
    @classmethod
    def get(cls, key, default=None):
        return cls.hashmap.get(key, default)


def task(cls):

    if issubclass(cls, Task):
        className = cls.__name__.lower()
        tasks = Register.get('tasks', {})
        tasks[className] = cls
        Register.set('tasks', tasks)

    return cls
